const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
const path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

const mode = process.env
let targetPath = ''
switch (mode.ENVIRONMENT) {
  case 'Development':
    // targetPath = 'http://192.168.10.37:5100'
    targetPath = 'http://192.168.10.48:4100' // 彪·
    break
  case 'UserAcceptanceTest':
    targetPath = 'http://192.168.10.31:5310'
    break
  case 'Production':
    targetPath = 'http://sd.zcdeer.com'
    break
}
module.exports = defineConfig({
  publicPath: './',

  transpileDependencies: true,
  lintOnSave: false,

  chainWebpack: (config) => {
    config.resolve.alias.set('@', path.join(__dirname, './src'))
    config.resolve.alias.set('@a', path.join(__dirname, './src/assets'))
  },

  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        PROCESS_ENV: JSON.stringify(mode),
        __VUE_OPTIONS_API__: 'true',
        __VUE_PROD_DEVTOOLS__: 'false',
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false'
      }),
      new CompressionWebpackPlugin({
        test: /\.js$|\.html$|\.css$/,
        threshold: 4096,
      }),
    ],
    devtool: "source-map",
  },

  devServer: {
    open: true,
    client: {
      overlay: false,
    },
    proxy: {
      '/ums': {
        target: targetPath,
        changeOrigin: true,
      },
      '/eas': {
        target: targetPath,
        changeOrigin: true,
      },
      '/mnc': {
        target: targetPath,
        changeOrigin: true,
      },
    },
  },
})
